<?php

namespace App\Http\Controllers\App;

use App\Http\Resources\App\SkillDetailResource;
use App\Models\Skill;
use App\Models\UserCourse;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class SkillController extends Controller
{
    public function index()
    {

    }

//技能信息
    public function detail(Request $request, Skill $skill)
    {
        return new SkillDetailResource($skill->load(['courses'=> function ($query)  {
            return $query->sortType();
        }, 'courses.users' => function ($query) use ($request) {
            return $query->where('user_id', $request->user()->id)->withPivot(UserCourse::OTHER_COLUMNS);
        }, 'careers' => function ($query) use ($request) {
            return $query->where('career_id', $request->career);
        }, 'users' => function ($query) use ($request) {
            return $query->where('user_id', $request->user()->id);
        }]));
    }

}
